package com.tq110.service.impl;

import com.tq110.dao.MusicMapper;
import com.tq110.dao.MusicTypeMapper;
import com.tq110.pojo.Music;
import com.tq110.pojo.MusicType;
import com.tq110.pojo.PageBean;
import com.tq110.service.MusicService;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("musicService")
@Transactional
public  class   MusicServiceImpl   implements   MusicService{
    @Resource
    protected   MusicMapper       musicDao;
    @Resource
    protected   MusicTypeMapper   musicTypeMapper;


    public MusicServiceImpl() {
        System.out.println("=======MusicServiceImpl实例化.....=============");
    }

    @Override
    public void addMusic(Music mc) {
        mc.setCreateTime(new Date());
        System.out.println(musicDao+"ershbfxdnrt============"+mc);
        musicDao.addMusic(mc);
    }

    @Override
    public void listAll(PageBean pageBean, Map<String, String> map) {
        String page=map.get("page");
        String pageSize=map.get("pageSize");
        String author=map.get("author");
        int pageInt=1;

        pageInt=Integer.valueOf(page);
        int pageSizeInt=Integer.valueOf(pageSize);
        Map<String, Object> argsMap =new HashMap<>();
        argsMap.put("from",(pageInt-1)*pageSizeInt);
        argsMap.put("size", pageSizeInt);
        argsMap.put("author",author);
        MusicType mt222=musicTypeMapper.findById("1005");
        System.out.printf("====rtndrjntd========"+mt222);
       Long  total=null;
                total=   musicDao.selectMusicTotal(argsMap);
        List<Music> datas=musicDao.selectMusic(argsMap);

        Music  mc22=musicDao.findById(2);
        Music  mc33=musicDao.findById22(2);
        System.out.println(total+"=====rtdndrt======"+datas);
        System.out.println(mt222+"==========fgndglistAll====="+mc22);
        System.out.println("BRB-------"+mc33);
    }

    @Cacheable(cacheNames = {"#i"})
    @Override
    public Music findById(int i) {
        return musicDao.findById(i);
    }


}
